package com.sky.controller.test1;

public class Test01 {
    public static void main(String[] args) {
        Animal dog = new Dog();
        dog.run();//编译看左,运行看右,对象多态,行为多态
        System.out.println(dog.name);//编译看左,运行看左
        Dog dog1 = (Dog) dog;//多态下不能调用子类的独有功能,强转
        dog1.run();
        if(dog instanceof Cat){
            Cat cat =  (Cat)dog;//类型转换错误Dog cannot be cast to com.sky.controller.test.Cat
        }
    }
}
 class Animal{
    String name = "animal";
    public void run(){
        System.out.println("Animal run");
    }
 }
 class Cat extends Animal{
    @Override
     public void run(){
         System.out.println("Cat run");
     }
 }
 class Dog extends Animal{
     String name = "dog";

    @Override
    public void run(){
        System.out.println("Dog run");
    }
    public void eat(){
        System.out.println("Dog eat");
    }
 }
